Registered S3 method overwritten by 'tsibble':
method from
as_tibble.grouped_df dplyr
Attaching package: 'tsibble'
The following objects are masked from 'package:base':
intersect, setdiff, union
library(dataRetrieval)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
# Example: Cache la Poudre River at Mouth (USGS site 06752260)poudre_flow <-readNWISdv(siteNumber ="06752260", # Download data from USGS for site 06752260parameterCd ="00060", # Parameter code 00060 = discharge in cfs)startDate ="2013-01-01", # Set the start dateendDate ="2023-12-31") |># Set the end daterenameNWISColumns() |># Rename columns to standard names (e.g., "Flow", "Date")mutate(Date =yearmonth(Date)) |># Convert daily Date values into a year-month format (e.g., "2023 Jan")group_by(Date) |># Group the data by the new monthly Datesummarise(Flow =mean(Flow)) # Calculate the average daily flow for each month
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
poudre_plot<-ggplot(poudre_tsibble, aes(x=Date, y=Flow))+geom_line(color="cornflowerblue")+labs(title="Flow Data from the Cache La Poudre USGS site 06752260",x="Date",y="Flow (cfs)")ggplotly(poudre_plot)
Sub Series
install.packages("feasts")
The downloaded binary packages are in
/var/folders/95/7bppnrhs19z4vp_sdb0lv9zr0000gn/T//Rtmp4JDb8x/downloaded_packages
library(feasts)
Loading required package: fabletools
gg_subseries(poudre_tsibble)
Plot variable not specified, automatically selected `y = Flow`
Description:
I see there is a defined pattern of high stream flow in May and June. Stream Flow is noticeably low from November to February. This makes sense as Colorado gets a lot of rain during the spring months including snow melt. This increase in precipitation increases stream discharge which will cause these spikes in data. Comparatively, the patterns of low stream flow can be explained by the periods of snow precipitation.
poudre_decompose_plot<-ggplot(poudre_decompose, aes(x=Date, y=season_adjust))+geom_line(color="forestgreen")+labs(title="Seaonsality and the Cache La Poudre", x="Date", y="Seasonality")ggplotly(poudre_decompose_plot)
Description:
Seasonality is the best window to look at when analyzing this data because it had a very clear pattern. The data represents water that is coming from the mountains which experience defined high and low flows depending on the season. It is also see a change in precipitation and other weather events when looking at seasonality. As the graph above shows, there is a noticeable decrease in precipitation from January 2014 to January 2024. This type of pattern is important to analyze to better decide how Colorado should change it’s water usage as we already have a deficit of available water.